package com.srcptit.java.training.kienbd.btvn1;

import java.io.IOException;
import java.util.Scanner;

public class Bai11IO {
    static String str;
    static void Input(){
        Scanner input = new Scanner(System.in);
        System.out.print("Nhap xau : ");
        str = input.nextLine();
    }
    public static void main(String[] args) {
        Input();
        // Xử lý ngoại lệ trong khi nhập các kiểu dữ liệu.
        // Kiểu int.
        Errorinteger();
        // Kiểu String.
        ErrorString();
        // Kiểu float.
        Errorfloat();
        // Kiểu double.
        Errordouble();
    }
    static void Errorinteger(){
        int n;
        try {
            n = Integer.parseInt(str);
            System.out.println("Yes! Dung kieu so nguyen.");
        }catch(NumberFormatException e) {
            System.out.println("Error!!! Du lieu khong dung kieu int.");
        }
    }
    static void ErrorString(){
        try {
            String newString = str;
            if( newString==null  )  throw new IOException();   
            System.out.println("Yes! Dung kieu string.");
        }catch(IOException e) {
            System.out.println("Error!!! Du lieu khong dung kieu String.");
        }
    }
    static void Errorfloat(){
        float n;
        try {
            n = Float.parseFloat(str);
            System.out.println("Yes! Dung kieu float.");
        }catch(NumberFormatException e) {
            System.out.println("Error!!! Du lieu khong dung kieu float.");
        }
    }
    static void Errordouble(){
        double n;
        try {
            n = Double.parseDouble(str);
            System.out.println("Yes! Dung kieu double.");
        }catch(NumberFormatException e) {
            System.out.println("Error!!! Du lieu khong dung kieu double.");
        }
    }
}
